#include <iostream>
#include "Log.hpp"
#include "Listener.hpp"
#include "Connection.hpp"
#include "EpollServer.hpp"

using namespace LogModule;

int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        std::cout << "Usage: " << argv[0] << " port" << std::endl;
        return 1;
    }
    ENABLE_CONSOLE_LOG();
    uint16_t local_port = std::stoi(argv[1]);
    EpollServer epoll_svr;

    auto conn = std::make_shared<Listener>(local_port);

    // Listener listen(local_port); // 完成具体工作的模块, 也有一个 listendsockfd
    // // 我们要把 listensockfd 封装成一个  Connection, Connection 托管给 EpollServer

    // auto conn = std::make_shared<Connection>(listen.Sockfd());
    // conn->InitCB(
    //     [&listen](){
    //         listen.Accepter();
    //     }, nullptr, nullptr
    // );

    // conn->SetEvents(EPOLLIN | EPOLLET);

    // auto conn = Factory::BuildConnection(listen.Sockfd(), EPOLLIN | EPOLLET, [&listen]()
    //                                     {listen.Accepter();}, nullptr, nullptr);

    // auto conn = std::make_shared<Connection>(listen.Sockfd());
    // func_t f = std::bind(Listener::Accepter, &listen, conn, nullptr);
    // conn->InitCB(f, nullptr, nullptr);

    epoll_svr.InsertConnection(conn);
    epoll_svr.Loop();
    
    return 0;
}